package com.leapp.sk.viewdelegate.notify

import android.content.Context
import android.support.v4.content.ContextCompat
import android.support.v4.widget.SwipeRefreshLayout
import android.text.TextUtils
import com.example.mvp.delegate.BaseAppDelegate
import com.example.mvp.view.RefreshListView
import com.example.mvp.view.SKTopBar
import com.leapp.sk.R
import com.leapp.sk.bean.NotifyObjEntity
import com.leapp.sk.ui.activity.notify.SystemNotifyActivity
import com.leapp.sk.ui.adapter.NotifyAdapter

/**
 * 系统通知视图托管类
 * @author  chaohaipeng  on 2018/8/15.
 */
class SystemNotifyDelegate : BaseAppDelegate() {
    /**
     * 适配器
     */
    var mAdapter: NotifyAdapter?=null
    override fun initWidget() {

    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_system_notify
    }
    /**
     * 设置标题
     */
    fun setTitle(title:String?){
        val topBar= getView<SKTopBar>(R.id.jtb_asn_system)
        if (!TextUtils.isEmpty(title)){
            topBar?.setTitle(title)
        }
        setEvent(topBar)
    }
    /**
     * 停止刷新
     */
    fun stopSwipRefresh() {
        val srl_asn_system_swipe = getView<SwipeRefreshLayout>(R.id.srl_asn_system_swipe)
        srl_asn_system_swipe.isRefreshing = false
    }
    /**
     * 初始化适配器
     */
    fun initAdapter(context:Context,list:List<NotifyObjEntity>,listener: SwipeRefreshLayout.OnRefreshListener){
        val lv_asn_system_list= getView<RefreshListView>(R.id.lv_asn_system_list)
        val srl_asn_system_swipe= getView<SwipeRefreshLayout>(R.id.srl_asn_system_swipe)
        srl_asn_system_swipe.setOnRefreshListener(listener)
        srl_asn_system_swipe.setColorSchemeColors(ContextCompat.getColor(context, R.color.color_19AD19))
        mAdapter= NotifyAdapter(getActivity(),list,true)
        lv_asn_system_list.adapter=mAdapter
    }
    /**
     * 设置设置事件
     */
    private  fun setEvent(topBar: SKTopBar){
        topBar?.setEventInterface(object : SKTopBar.EventInterface{
            override fun leftOnClick() {
                getActivity<SystemNotifyActivity>().finish()

            }
            override fun rightOnClick() {
            }

        })
    }

}